// src/floor/floor.service.ts
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Floor } from './floor.entity';

@Injectable()
export class FloorService {
    constructor(
        @InjectRepository(Floor)
        private floorRepository: Repository<Floor>,
    ) { }

    async getAllFloors(): Promise<Floor[]> {
        return this.floorRepository.find();
    }

    async getFloorById(id: number): Promise<Floor> {
        const floor = await this.floorRepository.findOne({ where: { id } });
        if (!floor) {
            throw new Error(`Floor with id ${id} not found`);
        }
        return floor;
    }

}